#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>

using namespace std;

string reverseWords(string s) {
    string word, res;
    for (auto c : s)
        if (c == ' ')
        {
            if (word.size())
                res = word + " " + res;
            word.clear();
        }
        else word += c;

    if (word.size())
        res = word + " " + res;

    res.pop_back();
    return res;
}